﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RN.ERP.DAL.Context;
using RN.ERP.Entity.ZBDLRY;


namespace RN.ERP.DAL.LcDAL
{
    public class KaoHeDAL
    {
        private ZBDL_Context zbdlcontext = new ZBDL_Context();

        public Dictionary<string, double> GetCorpDeDuckList(string corpGuids, string areaCode)
        {
            string sql = String.Format(@"SELECT CorpUserGuid, SUM(score) as SumScore  
                                         from v_e_DeDuck    
                                         where CorpUserGuid in ({0}) 
                                         AND bFlowStatus  like '1,%'   
                                         GROUP BY CorpUserGuid ", corpGuids);

            return zbdlcontext.Database.SqlQuery<RN.ERP.Entity.KeyValue>(sql).ToDictionary(a => a.Key, a => double.Parse(a.Value));

        }


        /// <summary>
        /// 查询企业考核指标详细信息,指定指标请使用condition中IndexIDList
        /// </summary>
        /// <param name="corpUserGuid"></param>
        /// <param name="condition"></param>
        /// <param name="areaCode"></param>
        /// <returns></returns>
        public  List<AssessmentDetailsEntity> GetCorpAssessmentDetails(string corpUserGuid, DTO.tb_dict_PerformanceAssessmentIndexModel condition, string areaCode)
        {
            string sql = String.Format(@" SELECT i.IndexTypeCode,i.IndexTypeName,i.TreeID, d.* FROM tb_dict_PerformanceAssessmentIndex i
                                        LEFT JOIN tb_AssessmentDetails d
                                        ON i.id=d.IndexID AND d.AssessmentYear=2014 AND  d.isdel=0 AND  d.CorpUserGuid='{0}' where 1=1 ",corpUserGuid);

            if(string.IsNullOrEmpty(condition.IndexTypeCode) &&condition.IndexTypeCode!="0")
            {
                sql+=string.Format(" and i.IndexTypeCode='{0}'",condition.IndexTypeCode);
            }
             if(condition.IndexIDList!=null&&condition.IndexIDList.Count>0)
            {
                sql += string.Format(" and i.id in ({0})", string.Join(",",condition.IndexIDList.ToArray()));
            }
             return zbdlcontext.Database.SqlQuery<AssessmentDetailsEntity>(sql).ToList();

           
        }
    }
}
